package com.study.service.impl;

import com.study.dao.ReadDao;
import com.study.pojo.Read;
import com.study.service.ReadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @Author Miss kun
 * @Date 2020/10/5 15:44
 * @Version 1.0
 */
@Service
public class ReadServiceImpl implements ReadService {

    @Autowired
    private ReadDao ReadDao ;

    @Override
    public int addContent(Read read) {
        return ReadDao.addContent(read);
    }

    @Override
    public Read getContent() {

        //获取文章的总数
        Integer readAllCount = ReadDao.getReadAllCount();

        //参生一个随机数
        Random random = new Random();
        int number= random.nextInt(readAllCount);
        //将随机数传入方法中，获取文章
        return ReadDao.getReadContentById(number);
    }
}
